home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 265 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: nntp.uio.no!usenet
  2. From: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Two questions - Pointer equality and ...
  5. Date: 1 Feb 1996 12:36:11 GMT
  6. Organization: University of Oslo, Norway
  7. Message-ID: <HBF.96Feb1133611@durin.uio.no>
  8. References: <4elq8a$j0b@taurus.fccc.edu> <TANMOY.96Jan30150808@qcd.lanl.gov>
  9.     <9601310155.AA07417@dxmint.cern.ch> <4emonm$kqc@fnclub.fnal.gov>
  10. NNTP-Posting-Host: durin.uio.no
  11. In-reply-to: b91926@fnclub.fnal.gov's message of 30 Jan 1996 21:47:02 -0600
  12.  
  13. In article <4emonm$kqc@fnclub.fnal.gov> b91926@fnclub.fnal.gov (David Sachs) writes:
  14. > I think it is rather unfortunate, that "const" came in so late.
  15. > Logically the proper tye of a string literal should be const char*
  16. > rather than char*, but there is just too much code written with
  17. > the old usage, for such a change to ever be feasible.
  18.  
  19. Well, maybe.  Consts that the programmer did not ask for can be a pain,
  20. because the const qualifier cannot be propagated from a function
  21. argument to the return value (or another function argument).  So we get
  22. into the habit of casting away consts, and will sometimes do it
  23. incorrectly.
  24.  
  25. To fix this, C would need something with this semantics (using semi-C++
  26. syntax):
  27.  
  28.     const <C>             /* Declare "C" as a "maybe-const" qualifier */
  29.     C char *              /* Use C */
  30.     strchr (<C> char*);      /* Set C from the function argument */
  31.  
  32.     const <C> long strtol (<C> char *str, C char **ptr, int base);
  33.  
  34.     /* Return the largest of two strings */
  35.     const <C1, C2> C1 C2 char *str_max (<C1> char *str1, <C2> char *str2);
  36.  
  37. I'm not sure whether to call that an argument for or against fixing the
  38. matter...
  39. -- 
  40. Regards,
  41.  
  42. Hallvard
  43.